//! @author Adam Emil Skoog
//! @date   2012-01-05

#include "CollisionMask.h"

namespace mehdi
 {
	CollisionMask::CollisionMask()
	:
	size    (.0f,.0f),
	position(.0f,.0f)
	 {
	 }

	CollisionMask::CollisionMask(const sf::Vector2f &size,const sf::Vector2f &position)
	:
	size    (size),
	position(position)
	 {
	 }

	CollisionMask &CollisionMask::setSize(const sf::Vector2f &size)
	 {
		this->size = size;
		return *this;
	 }

	const sf::Vector2f &CollisionMask::getSize() const
	 {
		return size;
	 }

	CollisionMask &CollisionMask::setPosition(const sf::Vector2f &position)
	 {
		this->position = position;
		return *this;
	 }

	const sf::Vector2f &CollisionMask::getPosition() const
	 {
		return position;
	 }

	bool CollisionMask::collidesWith(CollisionMask *const other,const sf::Vector2f &thisOffset,const sf::Vector2f &otherOffset) const
	 {
		const sf::FloatRect RECT_1(position.x + thisOffset.x,position.y + thisOffset.y,position.x + size.x + thisOffset.x,position.y + size.y + thisOffset.y),
							RECT_2(other->position.x + otherOffset.x,other->position.y + otherOffset.y,other->position.x + other->size.x + otherOffset.x,other->position.y + other->size.y + otherOffset.y);

		return (((RECT_1.Left >= RECT_2.Left && RECT_1.Left <= RECT_2.Right) ||
				 (RECT_1.Right >= RECT_2.Left && RECT_1.Right <= RECT_2.Right) ||
				 (RECT_1.Left <= RECT_2.Left && RECT_1.Right >= RECT_2.Left) ||
				 (RECT_2.Left <= RECT_1.Left && RECT_2.Right >= RECT_1.Left)) &&
				((RECT_1.Top >= RECT_2.Top && RECT_1.Top <= RECT_2.Bottom) ||
				 (RECT_1.Bottom >= RECT_2.Top && RECT_1.Bottom <= RECT_2.Bottom) ||
				 (RECT_1.Top <= RECT_2.Top && RECT_1.Bottom >= RECT_2.Top) ||
				 (RECT_2.Top <= RECT_1.Top && RECT_2.Bottom >= RECT_1.Top)));
	 }
 }
